#include "../Symboltable/SharedPointer.h"
#include <UnitTest++.h>

SUITE(SharedPointerTests) {
	TEST(PointerConstructor) {
		SharedPointer<int> ptr(new int(11));
		CHECK_EQUAL(*ptr, 11);
	}

	TEST(CopyConstructor) {
		SharedPointer<int> ptr1(new int(11));
		SharedPointer<int> ptr2(ptr1);
		CHECK_EQUAL(*ptr1, *ptr2);
	}

	TEST(Assignment) {
		SharedPointer<int> ptr1(new int(11));
		SharedPointer<int> ptr2(new int(22));
		ptr1 = ptr2;
		CHECK_EQUAL(*ptr1, *ptr2);
		CHECK_EQUAL(*ptr1, 22);
	}

	TEST(MultipleAssignmentViaConstructor) {
		SharedPointer<int> ptr1;
		SharedPointer<int> ptr2(new int(11));
		SharedPointer<int> ptr3(ptr1 = ptr2);
		CHECK_EQUAL(*ptr3, 11);
		CHECK_EQUAL(*ptr2, 11);
		CHECK_EQUAL(*ptr1, 11);
	}

	TEST(MultipleAssignment) {
		SharedPointer<int> ptr1, ptr2, ptr3(new int(11));
		ptr1 = ptr2 = ptr3;
		CHECK_EQUAL(*ptr1, *ptr2);
		CHECK_EQUAL(*ptr1, *ptr3);
		CHECK_EQUAL(*ptr2, *ptr3);
		CHECK_EQUAL(*ptr3, 11);
		CHECK_EQUAL(*ptr2, 11);
		CHECK_EQUAL(*ptr1, 11);
	}

	TEST(SelfAssignemnt) {
		SharedPointer<int> ptr(new int(11));
		ptr = ptr;
		CHECK_EQUAL(*ptr, 11);
	}

	TEST(MultipleAssignmentSelfAssignemnt) {
		SharedPointer<int> ptr1, ptr2, ptr3(new int(11));
		ptr3 = ptr2 = ptr1 = ptr3;
		CHECK_EQUAL(*ptr1, *ptr2);
		CHECK_EQUAL(*ptr1, *ptr3);
		CHECK_EQUAL(*ptr2, *ptr3);
		CHECK_EQUAL(*ptr3, 11);
		CHECK_EQUAL(*ptr2, 11);
		CHECK_EQUAL(*ptr1, 11);
	}

	TEST(Comparission) {
		SharedPointer<int> ptr1(new int(11));
		SharedPointer<int> ptr2(ptr1);
		CHECK(ptr1 == ptr2);
		CHECK(ptr2 == ptr1);
	}

	TEST(NullPointer) {
		SharedPointer<int> ptr(NULL);
	}

	TEST(BooleanExpression) {
		SharedPointer<int> ptr1(NULL);
		SharedPointer<int> ptr2(new int(11));
		CHECK(!ptr1);
		CHECK(ptr2);
	}
}
